<?php

$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$setting=$this->setting;
$tabs=array(
	array('op'=>'list','title'=>'售后群管理'),
	//array('op'=>'edit','title'=>'添加/编辑售后群'),
);
set_html('tabs',$tabs);
if($_RQ['op']=='list'){
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if($_RQ['status']!='all'){
		$params['status']=intval($_RQ['status']);
	}
	$return['params']['status']=$_RQ['status'];
	if($_RQ['storeid']){
		$params['storeid']=intval($_RQ['storeid']);
		$return['params']['storeid']=$_RQ['storeid'];
	}
	if($_RQ['workerid']){
		$params['workerid']=intval($_RQ['workerid']);
		$return['params']['workerid']=$_RQ['workerid'];
	}
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
    $orderby='id desc';
	$total='';
	$return['list']=$this->getall('class',$params,array(),'',$orderby);
	foreach($return['list'] as &$item){
		if($item['open_time']<time() && !$item['status']){
			$this->update('class',array('status'=>1),array('id'=>$item['id']));
		}
		$item['open_time']=date('Y-m-d',$item['open_time']);
		$item['set']='/jiaoxue.myclass/set/id='.$item['id'];
	}
	$htmls=array(
		'type'=>'list',
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：
		</br>这里显示本门店的售后群；
		','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'title','title'=>'售后群名称','type'=>'string'),
			array('name'=>'workerid','title'=>'售后主管','type'=>'select','options'=>'workers'),
			array('name'=>'workerid9','title'=>'售后助理售后','type'=>'select','options'=>'workers9'),
			array('name'=>'workerid10','title'=>'正课售后','type'=>'select','options'=>'workers10'),
			array('name'=>'kechengid','title'=>'绑定使用','type'=>'select','options'=>'kechengs'),
			array('title'=>'门牌号/容纳人数','type'=>'img_string',
			'data'=>array(
				array('title'=>'牌号：','name'=>'menpai'),
				array('title'=>'容纳人数：','name'=>'rongnum')
				)
			),
			array('title'=>'用户人数/休转退','type'=>'img_string',
			'data'=>array(
				array('title'=>'用户人数：','name'=>'xueshengnum'),
				array('title'=>'实际人数：','name'=>'rongnum'),
				array('title'=>'休转退：','name'=>'rongnum')
				)
			),
			array('name'=>'keshi','title'=>'课时','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'radiomodal','options'=>'status','action'=>'set'),
			array('name'=>'open_time','title'=>'开班时间','type'=>'string'),
		),'action'=>array(
			array('type'=>'modal','op'=>'set','title'=>'设置状态'),
			array('type'=>'href','title'=>'前往管理售后群','action'=>'/xuesheng.danganlist/fromclass/status=all'),
		)),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'售后群名称','name'=>'title','help'=>''),
			array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'workerid','width'=>'15','title'=>'售后主管','type'=>'select','options'=>'workers'),
		),
	);
	//$return['stores']=$this->getall('store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'));
	$return['workers']=$this->getall('worker',array('role'=>11,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['workers9']=$this->getall('worker',array('role'=>9,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['workers10']=$this->getall('worker',array('role'=>10,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['kechengs']=$this->getall('kecheng',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['status']=$this->class_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=$post['id'];
		$update=array('status'=>$post['status']);
		pdo_update('jy_yxw_class',$update,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		if($post['status']==2){
			$this->update('xuesheng',array('status'=>13),array('classid'=>$id,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
		}elseif($post['status']==1){
			$this->update('xuesheng',array('status'=>12),array('classid'=>$id,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
		}elseif($post['status']==0){
			$this->update('xuesheng',array('status'=>11),array('classid'=>$id,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
		}
		exi('操作成功！','','/jiaoxue.myclass//status=all');
	}
	if($_RQ['id']){
		$item=pdo_get('jy_yxw_class',array('uniacid'=>$_SESSION['uniacid'],'id'=>$_RQ['id']));
	}else{
		exi('请先选择售后群','error');
	}
	$return['item']=$item;	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'设置状态',
	);
	$htmls['edit']=array(
		array('type'=>'radio','title'=>'设置状态','name'=>'status','options'=>'status'),
	);
	$return['status']=$this->class_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='status2'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('参数错误！','error');
	}
	$this->update('class',array('status'=>2),array('id'=>$id,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
	$this->update('xuesheng',array('status'=>13),array('classid'=>$id,'storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！');
}
?>